import urllib.request
from urllib.request import urlretrieve


def getImg(str1):
    list1 = []
    while 1:
        firstSign = str1.find('img src="')
        endSign = str1.find('.jpg')
        if firstSign == -1 or endSign == -1:
            break
        list1.append("https://www.tute.edu.cn/" +
                     str1[firstSign + 15:endSign + 4])
        str1 = str1[endSign + 4:]
    return list1


url = 'https://www.tute.edu.cn/xysh/yxtzsd/1.htm'

response = urllib.request.urlopen(url)
cc = ""
cc = response.read().decode('utf-8')

list1 = getImg(cc)
print("总共找到了{0}张图片".format(len(list1)))


num = int(input("请输入要下载的图片数："))
for i in range(num):
    urlretrieve(list1[i], 'img{0}.jpg'.format(i))
print("下载成功")
